package cn.bigcontainer.alt.meta.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.bigcontainer.alt.common.entity.BigMap;
import cn.bigcontainer.alt.common.exception.BigResultCode;
import cn.bigcontainer.alt.common.util.BigConstant;
import cn.bigcontainer.alt.meta.service.ListPropertyService;

/**
 * 列表列获取json数据的接口
 * @author jiaod
 *
 */
@Controller
@RequestMapping("/meta/listproperty")
@SessionAttributes(BigConstant.SESSION_USER)
public class ListPropertyController {

	@Resource
	private ListPropertyService listPropertyService;

	/**
	 * 执行sql
	 * @param req
	 * @param map
	 * @return
	 */
    @RequestMapping("/sql")
	@ResponseBody
    public BigResultCode executeSql (String id, String[] listPropertyData, @RequestParam Map<String, Object> req, Map<String, Object> map) {
    	Map<String, Object> values = listPropertyService.querySql(id, listPropertyData, new BigMap<String, Object>().bigPutAll(req));
        return BigResultCode.getSuccessCode().setContent(values);
    }
    
    /**
	 * 修改MObject的部分属性
	 * @param req
	 * @param map
	 * @return
	 */
    @RequestMapping("/m2cm")
	@ResponseBody
    public BigResultCode updateObject (String id, String[] listPropertyData) {
    	Map<String, Object> values = listPropertyService.getListPropertyValue (id, listPropertyData);
        return BigResultCode.getSuccessCode().setContent(values);
    }
}
